
from flask import Flask, render_template,request
app=Flask(__name__)
@app.route("/")
def hello() -> str:
    return 'hello world from Flash!'
@app.route("/search4",methods=['post','get'])
def do_search() -> 'html':
    phrase = request.form['phrase']
    letters=request.form['letters']
    title = '这是搜索结果的title'
    results = str(search4letters(phrase, letters))
    log_request(request,results)
    return render_template('result.html',
                           the_phrase=phrase,
                           the_letters=letters,
                           the_title=title,
                           the_result=results,)
@app.route("/entry")
def entry_page() -> 'html':
    return render_template('entry.html',the_title='WWH标题1')

def search4letters(strA:str, strB:str)->set:
    return set(strA).intersection(set(strB))


def log_request(req:'flask_request',res:str) ->None:
    with open('vsearch.log','a') as log:
        #打印普通的请求日志
        #print(req,res,file=log)
        #请求对象的所有属性，经过dir函数转换之后传给str
        #print(str(dir(req)),res,file=log)
        ##记录特定的Web请求属性
        #print(req.form,file=log)
        #print(req.remote_addr, file=log)
        #print(req.user_agent, file=log)

        ##记录单行分割数据
        #print(req.form, file=log, end='|')
        #print(req.remote_addr, file=log, end='|')
        #print(req.user_agent, file=log, end='|')
        #print(res, file=log)

        ##最后一次修改日志记录代码--用一个print打印多个对象
        print(req.form, req.remote_addr, req.user_agent, res, file=log , sep='|')

if(__name__=='__main__'):
    app.run(debug=True)

